/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package warehouse.forms;

import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Mark
 */
public class MainMenu extends javax.swing.JPanel {

    /**
     * Creates new form MainMenu
     */
    public MainMenu() {
        initComponents();        
        DefaultTableModel tm = (DefaultTableModel) inventoryTable.getModel();
        tm.setRowCount(0);
        warehouseInventory().stream().forEach((line) -> {
            tm.addRow(line.substring(line.indexOf(",") + 1).split(","));
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        PurchaseButton = new javax.swing.JButton();
        ReturnButton = new javax.swing.JButton();
        ExitButton = new javax.swing.JButton();
        Panel = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        inventoryTable = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        StoreListTable = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout());

        PurchaseButton.setText("Purchase");
        PurchaseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PurchaseButtonActionPerformed(evt);
            }
        });
        jPanel1.add(PurchaseButton);

        ReturnButton.setText("Return");
        jPanel1.add(ReturnButton);

        ExitButton.setText("Exit");
        jPanel1.add(ExitButton);

        add(jPanel1, java.awt.BorderLayout.PAGE_END);

        inventoryTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Name", "Description", "Price", "Quantity"
            }
        ));
        jScrollPane1.setViewportView(inventoryTable);

        Panel.addTab("Inventory", jScrollPane1);

        StoreListTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Store id", "Store Name", "Location", "Contact"
            }
        ));
        jScrollPane2.setViewportView(StoreListTable);

        Panel.addTab("Store List", jScrollPane2);

        add(Panel, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents

    private void PurchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PurchaseButtonActionPerformed
        Purchase pur = new Purchase();
        pur.setVisible(true);
    }//GEN-LAST:event_PurchaseButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ExitButton;
    private javax.swing.JTabbedPane Panel;
    private javax.swing.JButton PurchaseButton;
    private javax.swing.JButton ReturnButton;
    private javax.swing.JTable StoreListTable;
    private javax.swing.JTable inventoryTable;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

    private static java.util.List<java.lang.String> warehouseInventory() {
        store.StoreWebService_Service service = new store.StoreWebService_Service();
        store.StoreWebService port = service.getStoreWebServicePort();
        return port.warehouseInventory();
    }
}
